package sqladvisor

import (
	"github.com/romberli/das/pkg/message"
	"github.com/romberli/go-util/config"
)

func init() {
	initServiceDebugMessage()
	initServiceInfoMessage()
	initServiceErrorMessage()
}

// Message code
const (
	// debug
	DebugSQLAdvisorGetFingerprint              = 105001
	DebugSQLAdvisorGetSQLID                    = 105002
	DebugSQLAdvisorAdviceByDBID                = 105003
	DebugSQLAdvisorAdviceByDBHostInfoAndDBName = 105004

	// info
	InfoSQLAdvisorGetFingerprint              = 205001
	InfoSQLAdvisorGetSQLID                    = 205002
	InfoSQLAdvisorAdviceByDBID                = 205003
	InfoSQLAdvisorAdviceByDBHostInfoAndDBName = 205004

	// error
	ErrSQLAdvisorAdviceByDBID                = 405001
	ErrSQLAdvisorAdviceByDBHostInfoAndDBName = 405002
)

func initServiceDebugMessage() {
	message.Messages[DebugSQLAdvisorGetFingerprint] = config.NewErrMessage(
		message.DefaultMessageHeader, DebugSQLAdvisorGetFingerprint,
		"sqladvisor: get fingerprint. sql_text: %s, message: %s")
	message.Messages[DebugSQLAdvisorGetSQLID] = config.NewErrMessage(
		message.DefaultMessageHeader, DebugSQLAdvisorGetSQLID,
		"sqladvisor: get sql id. sql_text: %s, message: %s")
	message.Messages[DebugSQLAdvisorAdviceByDBID] = config.NewErrMessage(
		message.DefaultMessageHeader, DebugSQLAdvisorAdviceByDBID,
		"sqladvisor: advice by db id. db_id: %d, sql_text: %s, message: %s")
	message.Messages[DebugSQLAdvisorAdviceByDBHostInfoAndDBName] = config.NewErrMessage(
		message.DefaultMessageHeader, DebugSQLAdvisorAdviceByDBHostInfoAndDBName,
		"sqladvisor: advice by host info and db name. host_ip: %s, port_num: %d, db_name: %s, sql_text: %s, message: %s")
}

func initServiceInfoMessage() {
	message.Messages[InfoSQLAdvisorGetFingerprint] = config.NewErrMessage(
		message.DefaultMessageHeader, InfoSQLAdvisorGetFingerprint,
		"sqladvisor: get fingerprint completed. sql_text: %s, fingerprint: %s")
	message.Messages[InfoSQLAdvisorGetSQLID] = config.NewErrMessage(
		message.DefaultMessageHeader, InfoSQLAdvisorGetSQLID,
		"sqladvisor: get sql id completed. sql_text: %s, sql_id: %s")
	message.Messages[InfoSQLAdvisorAdviceByDBID] = config.NewErrMessage(
		message.DefaultMessageHeader, InfoSQLAdvisorAdviceByDBID,
		"sqladvisor: advice by db id completed. db_id: %d, sql_text: %s, advice: %s")
	message.Messages[InfoSQLAdvisorAdviceByDBHostInfoAndDBName] = config.NewErrMessage(
		message.DefaultMessageHeader, InfoSQLAdvisorAdviceByDBHostInfoAndDBName,
		"sqladvisor: advice by host info and db name completed. host_ip: %s, port_num: %d, db_name: %s, sql_text: %s, advice: %s")
}

func initServiceErrorMessage() {
	message.Messages[ErrSQLAdvisorAdviceByDBID] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrSQLAdvisorAdviceByDBID,
		"sqladvisor: advice by db id failed. db_id: %d, sql_text: %s")
	message.Messages[ErrSQLAdvisorAdviceByDBHostInfoAndDBName] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrSQLAdvisorAdviceByDBHostInfoAndDBName,
		"sqladvisor: advice by host info and db name failed. host_ip: %s, port_num: %d, db_name: %s, sql_text: %s")
}
